package com.easyadmin.modules.stock.service.impl;

import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.modules.stock.domain.SysFactorEntity;
import com.easyadmin.modules.stock.domain.SysFuturesEntity;
import com.easyadmin.modules.stock.domain.SysInvestModelEntity;
import com.easyadmin.modules.stock.mapper.SysInvestModelDao;
import com.easyadmin.modules.stock.service.SysInvestModelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;


@Service("sysInvestModelService")
public class SysInvestModelServiceImpl extends ServiceImpl<SysInvestModelDao, SysInvestModelEntity> implements SysInvestModelService {


    @Autowired
    SysInvestModelDao sysInvestModelDao;

    @Override
    public PageInfo<SysInvestModelEntity> queryPage(SysInvestModelEntity sysFuturesEntity, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<SysInvestModelEntity> data =sysInvestModelDao.selectList(new QueryWrapper<SysInvestModelEntity>()
                .lambda().eq(StringUtils.isNotBlank(sysFuturesEntity.getModelType()),
                        SysInvestModelEntity::getModelType,sysFuturesEntity.getModelType())
                .like(StringUtils.isNotBlank(sysFuturesEntity.getModelName()),
                        SysInvestModelEntity::getModelName,sysFuturesEntity.getModelName()));
        return new PageInfo<>(data);
    }

    @Override
    public boolean update(SysInvestModelEntity sysInvestModelEntity) {
        Integer result = sysInvestModelDao.updateById(sysInvestModelEntity);
        return result > 0;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchRemove(String[] ids) {
        for(String  id:ids){
            sysInvestModelDao.deleteById(id);
        }
        return true;
    }
}